package com.lanyou.esb.cook.proxy.service.push.impl;

import com.lanyou.esb.cook.proxy.entity.IfAvgResTimes;
import com.lanyou.esb.cook.proxy.redis.proxy.impl.IfAvgResTimesJedisProxy;
import com.lanyou.esb.cook.proxy.redis.proxy.impl.IfAvgResTimesKeysJedisProxy;
import com.lanyou.esb.cook.proxy.service.push.Push;

/**
 * 接口平均响应时间消息推送服务
 * 
 * @author Davey.wu
 */
public class IfAvgResTimesPushImpl extends BasePush<IfAvgResTimes> implements
		Push<IfAvgResTimes> {
	/** Redis代理接口 **/
	private IfAvgResTimesJedisProxy jedisProxy;
	/** Redis代理接口 **/
	private IfAvgResTimesKeysJedisProxy jedisProxyKeys;

	/**
	 * 将接口平均响应时间存入Redis
	 *
	 * @param ifAvgResTimes
	 */
	@Override
	public void pushToRedis(IfAvgResTimes ifAvgResTimes) throws Exception {
		IfAvgResTimes temp = jedisProxy.get(jedisProxy
				.getKeyFromObject(ifAvgResTimes));
		// 已存在，累加
		if (temp != null) {
			jedisProxy.setex(jedisProxy.getKeyFromObject(temp), temp);
		}
		// 不存在，加入
		else {
			String key = jedisProxy.getKeyFromObject(ifAvgResTimes);
			jedisProxy.setex(key, ifAvgResTimes);
			jedisProxyKeys.rpush(jedisProxyKeys.getKey(), key);
		}
	}

	public IfAvgResTimesJedisProxy getJedisProxy() {
		return jedisProxy;
	}

	public void setJedisProxy(IfAvgResTimesJedisProxy jedisProxy) {
		this.jedisProxy = jedisProxy;
	}

	public IfAvgResTimesKeysJedisProxy getJedisProxyKeys() {
		return jedisProxyKeys;
	}

	public void setJedisProxyKeys(IfAvgResTimesKeysJedisProxy jedisProxyKeys) {
		this.jedisProxyKeys = jedisProxyKeys;
	}

}
